home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / asm_subr.arc / I162BCD < prev    next >
Encoding:
Text File  |  1985-12-22  |  2.0 KB  |  86 lines

  1. ;-------------------------i162bcd routine begins--------------------------+
  2. ; from BLUEBOOK OF ASSEMBLY ROUTINES FOR IBM PC & XT.
  3. ;         page : 70
  4. ;
  5. ; NAME I162BCD
  6. ; ROUTINE FOR CONVERSION FROM 16-BIT BINARY TO BCD
  7. ;
  8. ; FUNCTION: This routine converts from internal 16-bit binary numbers to
  9. ; numbers stored in internal BCD format
  10. ;
  11. ; INPUT: Upon entry a 16-bit binary number is in the DX register
  12. ;
  13. ; OUTPUT: Upon return a 36-digit number is stored in BCD form in an 18-
  14. ; byte buffer in the data segment called BCDBUFF
  15. ;
  16. ; REGISTERS USED:  No registers are modified.  DX is used for input.
  17. ;
  18. ; SEGMENTS REFERENCED:  DATAS is a data segment which contains the buffer
  19. ; BDCBUFF
  20. ;
  21. ; ROUTINES CALLED:  None
  22. ; SPECIAL NOTES: None
  23. ;
  24. ; ROUTIINE TO CONVERT FROM INTERNAL 16-BIT BINARY TO INTERNAL BCD
  25. ;
  26. i162bcd    proc    far
  27. ;
  28.     push    ds        ; save registers
  29.     push    si
  30.     push    dx
  31.     push    cx
  32.     push    ax
  33. ;
  34. ; set up the data segment
  35.     mov    ax,datas    ; point to data segment
  36.      mov    ds,ax
  37. ;
  38. ; a binary number is in DX
  39. ;
  40. ; clear bcd buffer
  41.     lea    di,bcdbuff    ; point to buffer
  42.     mov    al,0        ; zero byte
  43.     mov    cx,18        ; bcdbuff size
  44. ;
  45. i162bcd1:
  46.     mov    [di],al        ; clear byte
  47.     inc    di        ; point to next one
  48.     loop    i162bcd1
  49. ;
  50. ; put the digits in a buffer
  51.     lea    di,bcdbuff    ; point to bcdbuff
  52. ;
  53. i162bcd2
  54.     mov    ax,dx        ; numerator
  55.     mov    dx,0        ; clear upper half
  56.     mov    cx,10        ; divisor of 10
  57.     div    cx        ; divide
  58.     xchg    ax,dx        ; get quotient
  59.     mov    bl,al        ; save digit
  60. ;
  61.     mov    ax,dx        ; numerator
  62.     mov    dx,0        ; clear upper half
  63.     mov    cx,10        ; divisor of 10
  64.     div    cx        ; divide
  65.     xchg    ax,dx        ; get quotient
  66. ;
  67.     mov    cl,4        ; for a count of 4
  68.     rol    al,cl        ; rotate byte
  69.     and    al,0Fh        ; just the digit
  70.     or    al,bl        ; combine digits
  71. ;
  72.     mov    [di],al        ; put in buffer
  73.     inc    di        ; next byte
  74.     cmp    dx,0        ; done ?
  75.     jnz    i162bcd2    ; nope
  76. ;
  77.     pop    ax        ; yes, done...restore registers
  78.     pop    cx
  79.     pop    dx
  80.     pop    di
  81.     pop    ds
  82.     ret            ; return
  83. ;
  84. i162bcd    endp
  85. ;-------------------------i162bcd routine ends---------------------------+
  86.